package com.hkts.management.unattended.poundroom.service.serviceimpl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hkts.management.unattended.poundroom.entity.YbMutualInventory;
import com.hkts.management.unattended.poundroom.entity.YbMutualPovouch;
import com.hkts.management.unattended.poundroom.mapper.YbMutualPovouchMapper;
import com.hkts.management.unattended.poundroom.service.IYbMutualPovouchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author zy
 * @since 2021-10-13
 */
@Service
@Transactional
@DS("slave")
public class YbMutualPovouchSlaveServiceImpl extends ServiceImpl<YbMutualPovouchMapper, YbMutualPovouch> {


    @Autowired
    private YbMutualPovouchMapper ybMutualPovouchMapper;

    public IPage<YbMutualPovouch> selectPage(Page<YbMutualPovouch> page, YbMutualPovouch ybMutualPovouch) {
        QueryWrapper<YbMutualPovouch> query = Wrappers.query();
        return ybMutualPovouchMapper.selectPage(page, query);
    }


    public List<YbMutualPovouch> selectList(YbMutualPovouch ybMutualPovouch) {
        QueryWrapper<YbMutualPovouch> query = Wrappers.query();
        return ybMutualPovouchMapper.selectList(query);
    }
    public List<YbMutualPovouch> getUpdateTimeData(LocalDateTime updateTime ,int flag){
        QueryWrapper<YbMutualPovouch> query = Wrappers.query();
        query.select("top 1000 AutoID,ID, cPOID, dPODate, cPTCode, cDepCode, cDepName, cPersonCode, cPersonName, cVenCode, cVenAbbName,cState, cInvCode, cInvName, cInvStd, cComUnitName, iQuantity, iTaxPrice,iReceivedQTY,LJRKSL,dArriveDate, bDel, doptTime, dcreateTime, dmodifyTime, ddeleteTime, u8optStatus, bmutualStatus ");
        query.lambda().gt(updateTime!=null,YbMutualPovouch::getDoptTime,updateTime);
        query.orderByAsc("AutoID");
        if(flag!=0){
            Integer count=flag*1000;
            Integer maxId=ybMutualPovouchMapper.getAutoIdMax(count);
            query.lambda().ge(YbMutualPovouch::getAutoID,maxId);
        }
        return ybMutualPovouchMapper.selectList(query);
    }
    public Integer getUpdateTimeCount(LocalDateTime updateTime){
        QueryWrapper<YbMutualPovouch> query = Wrappers.query();
        query.lambda().gt(updateTime!=null,YbMutualPovouch::getDoptTime,updateTime);
        Integer count=ybMutualPovouchMapper.selectCount(query);
        double flag=count;
        double total=flag/1000;
        return (int)Math.ceil(total);
    }
    public Integer getBmutualStatusCount(){
        QueryWrapper<YbMutualPovouch> query = Wrappers.query();
        query.lambda().eq(YbMutualPovouch::getBmutualStatus,0);
        Integer count=ybMutualPovouchMapper.selectCount(query);
        double flag=count;
        double total=flag/1000;
        return (int)Math.ceil(total);
    }
    public List<YbMutualPovouch> getBmutualStatuData(int flag){
        QueryWrapper<YbMutualPovouch> query = Wrappers.query();
        query.select("top 1000 AutoID,ID, cPOID, dPODate, cPTCode, cDepCode, cDepName, cPersonCode, cPersonName, cVenCode, cVenAbbName,cState, cInvCode, cInvName, cInvStd, cComUnitName, iQuantity, iTaxPrice,iReceivedQTY,LJRKSL,dArriveDate, bDel, doptTime, dcreateTime, dmodifyTime, ddeleteTime, u8optStatus, bmutualStatus ");
        query.lambda().eq(YbMutualPovouch::getBmutualStatus,0);
        query.orderByAsc("AutoID");
        if(flag!=0){
            Integer count=flag*1000;
            Integer maxId=ybMutualPovouchMapper.getAutoIdMax(count);
            query.lambda().ge(YbMutualPovouch::getAutoID,maxId);
        }
        return ybMutualPovouchMapper.selectList(query);
    }

}
